﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    /// <summary>
    /// Summary description for WXYWService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class WXYWService : System.Web.Services.WebService
    {
        public WXYWService()
        { }
        [WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public string[] GetAccessory(string prefixText, int count)
        {
            AccessoryService service = new AccessoryService();
            IQueryable<Accessory> list = service.GetAccessory(prefixText);
            List<string> listStr = new List<string>();
            foreach (Accessory acc in list)
            {
                if (!listStr.Contains(acc.ModelNO))
                {
                    listStr.Add(acc.ModelNO);
                }
            }
            return listStr.Take(count).ToArray();
        }

        [WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public string[] GetConnectPerson(string prefixText, int count)
        {
            UserService service = new UserService();
            IQueryable<User> list = service.GetUserConnectPersonByPrefixText(prefixText, count);

            List<string> listStr = new List<string>();
            foreach (User us in list)
            {
                listStr.Add(us.ContactPerson);
            }

            return listStr.ToArray();
        }

        [WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public string[] GetCompany(string prefixText, int count)
        {
            UserService service = new UserService();
            IQueryable<User> list = service.GetUserCompanyByprefixText(prefixText, count);

            List<string> listStr = new List<string>();
            foreach (User us in list)
            {
                listStr.Add(us.FullName);
            }

            return listStr.ToArray();
        }

        // 获取零件列表
        [WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public string[] GetAccessoryOfProvider(string prefixText, int count)
        {
            ProviderService providerService = new ProviderService();
            IQueryable<ProviderAccessory> accessoryList = providerService.GetAccessoryByPrefix(prefixText, count);
            List<string> listStr = new List<string>();
            foreach (ProviderAccessory accessory in accessoryList)
            {
                listStr.Add(accessory.ModelNumber);
            }
            return listStr.ToArray();
        }
    }
}
